home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / helper / source / event.c < prev    next >
Text File  |  1991-10-18  |  4KB  |  195 lines

  1. /*
  2.     マウス イベント処理ライブラリ
  3.  
  4.     1990.9.11    Make By ken
  5. */
  6. #include    <stdio.h>
  7. #include    <stdlib.h>
  8. #include    <string.h>
  9. #include    <mos.h>
  10. #include    "graphic.h"
  11. #include    "event.h"
  12. #include    "coldef.h"
  13.  
  14. #define    TRUE    1
  15. #define    FALSE    0
  16. #define    ERR    (-1)
  17.  
  18. int    EVT_msg_no=ERR;
  19.  
  20. void    EVT_free(register EVENT *tp)
  21. {
  22.     register EVENT *ep;
  23.  
  24.     while ( tp != NULL ) {
  25.     ep = tp->next;
  26.     free(tp);
  27.     tp = ep;
  28.     }
  29. }
  30. EVENT    *EVT_set(EVENT *tp,int no,
  31.         int x1,int y1,int x2,int y2,void (*proc)())
  32. {
  33.     register EVENT *ep;
  34.  
  35.     if ( (ep = (EVENT *)malloc(sizeof(EVENT))) == NULL )
  36.     return tp;
  37.  
  38.     ep->next = tp;
  39.     ep->actp = NULL;
  40.     ep->now = EVT_NON;
  41.     ep->no = no;
  42.     ep->x1 = x1;
  43.     ep->y1 = y1;
  44.     ep->x2 = x2;
  45.     ep->y2 = y2;
  46.     ep->proc = proc;
  47.  
  48.     return ep;
  49. }
  50. static int    EVT_chk(register EVENT *ep)
  51. {
  52.     int     fg;
  53.     int     sw,x,y;
  54.  
  55.     MOS_rdpos(&sw,&x,&y);
  56.     fg = (x >= ep->x1 && x <= ep->x2 && 
  57.       y >= ep->y1 && y <= ep->y2 ) ? TRUE:FALSE;
  58.  
  59.     switch(ep->now) {
  60.     case EVT_OFF_MOS:
  61.     case EVT_MOVE_MOS:
  62.     case EVT_DLSEL_MOS:
  63.     case EVT_SELECT_MOS:
  64.     ep->now = EVT_NON;
  65.     break;
  66.  
  67.     case EVT_NON:
  68.     if ( fg != FALSE ) {
  69.         ep->now = (sw != 0 ? EVT_CLIP_MOS:EVT_ON_MOS);
  70.         (*ep->proc)(ep);
  71.     }
  72.     break;
  73.  
  74.     case EVT_ON_MOS:
  75.     if ( fg != FALSE ) {
  76.         if ( sw != 0 ) {
  77.             ep->now = EVT_CLIP_MOS;
  78.             (*ep->proc)(ep);
  79.         }
  80.     } else {
  81.         ep->now = EVT_OFF_MOS;
  82.         (*ep->proc)(ep);
  83.     }
  84.     break;
  85.  
  86.     case EVT_CLIP_MOS:
  87.     if ( fg != FALSE ) {
  88.         if ( sw == 0 ) {
  89.             ep->now = EVT_SELECT_MOS;
  90.             (*ep->proc)(ep);
  91.         }
  92.     } else {
  93.         ep->now = (sw != 0 ? EVT_DOLACK_MOS : EVT_MOVE_MOS);
  94.         (*ep->proc)(ep);
  95.     }
  96.     break;
  97.  
  98.     case EVT_DOLACK_MOS:
  99.     if ( sw == FALSE )
  100.         ep->now = EVT_DLSEL_MOS;
  101.     (*ep->proc)(ep);
  102.     break;
  103.  
  104.     case EVT_REP_MOS:
  105.     if ( fg != FALSE ) {
  106.         if ( sw == 0 ) {
  107.             ep->now = EVT_SELECT_MOS;
  108.             (*ep->proc)(ep);
  109.         } else
  110.             (*ep->proc)(ep);
  111.     } else {
  112.         ep->now = (sw != 0 ? EVT_DOLACK_MOS : EVT_MOVE_MOS);
  113.         (*ep->proc)(ep);
  114.     }
  115.     break;
  116.     }
  117.  
  118.     return ep->now;
  119. }
  120. void    EVT_loop(register EVENT *tp)
  121. {
  122.     register EVENT *ep;
  123.  
  124.     if ( tp == NULL )
  125.     return;
  126.  
  127.  
  128.     if ( (ep = tp->actp) != NULL ) {
  129.     if ( EVT_chk(ep) == EVT_NON )
  130.         tp->actp = NULL;
  131.     return;
  132.     }
  133.  
  134.     ep = tp;
  135.     while ( ep != NULL ) {
  136.     if ( EVT_chk(ep) != EVT_NON ) {
  137.         tp->actp = ep;
  138.         return;
  139.     }
  140.     ep = ep->next;
  141.     }
  142. }
  143.  
  144. void    EVT_proc(EVENT *ep)
  145. {
  146.     static int old_mos=ERR;
  147.  
  148.     switch(ep->now) {
  149.  
  150.     case EVT_CLIP_MOS:
  151.     MOS_disp(OFF);
  152.     DSP_box(ep->x1,ep->y1,ep->x2,ep->y2,8,M_XOR);
  153.     MOS_disp(ON);
  154.     case EVT_ON_MOS:
  155.     if ( old_mos == ERR )
  156.         old_mos = now_mos;
  157.     DSP_mos(1);
  158.     break;
  159.  
  160.     case EVT_SELECT_MOS:
  161.     EVT_msg_no = ep->no;
  162.     case EVT_DOLACK_MOS:
  163.     ep->now = EVT_NON;
  164.     case EVT_MOVE_MOS:
  165.     MOS_disp(OFF);
  166.     DSP_box(ep->x1,ep->y1,ep->x2,ep->y2,8,M_XOR);
  167.     MOS_disp(ON);
  168.     case EVT_OFF_MOS:
  169.     DSP_mos(old_mos);
  170.     old_mos = ERR;
  171.     break;
  172.     }
  173. }
  174. EVENT    *EVT_sw(EVENT *tp,int no,int x,int y,int cc,int bc,char *str)
  175. {
  176.     int     x1,y1,x2,y2;
  177.  
  178.     x1 = x - 4;
  179.     y1 = y - 2;
  180.     x2 = x + strlen(str) * 8 + 3;
  181.     y2 = y + 17;
  182.  
  183.     DSP_wbox(x1,y1,x2,y2,LINE_COL,bc,M_PSET);
  184.     gputs(x,y,cc,bc,str);
  185.  
  186.     return EVT_set(tp,no,x1,y1,x2,y2,EVT_proc);
  187. }
  188. int    EVT_wait(EVENT *tp)
  189. {
  190.     EVT_msg_no = ERR;
  191.     while ( EVT_msg_no == ERR )
  192.     EVT_loop(tp);
  193.     return EVT_msg_no;
  194. }
  195.